import java.util.Arrays;
import java.util.Locale;

class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Test {
    //字符串中的第一个唯一字符
    public int firstUniqChar(String s) {
        int[] count = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count[ch - 'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (count[ch - 'a'] == 1) {
                return i;
            }
        }
        return -1;

    }

    //字符串最后一个单词的长度(没有特殊字符)
    public int lengthOfLastWord(String s) {
        int count1 = s.lastIndexOf(" ");
        return s.length() - count1;

    }

    //验证回文串
    public boolean isEffective(char ch) {
        //验证是否为数字和字母（有效字符）

        return Character.isLetterOrDigit(ch);
    }

    public boolean isPalindrome(String s) {
        s = s.toLowerCase();//全部小写
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            while (left < right && !isEffective(s.charAt(left))) {
                left++;
            }
            while (left < right && !isEffective(s.charAt(right))) {
                right--;
            }
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }

    //统计字符串中的单词数
    public int countSegments(String s) {
        String s1 = s.trim();//去掉左右两边的空格数
        int count = 0;
        String[] strings = s.split(" ");//用空格将string分组
        for (int i = 0; i < strings.length; i++) {
            if (strings[i].length() != 0) {
                count++;
            }
        }
        return count;
    }

    //转换成小写字符
    public String toLowerCase(String s) {
        StringBuilder stringBuilder=new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if(ch>='A'&&ch<='Z'){
                stringBuilder.append((char)(ch+32));
            }else {
                stringBuilder.append(ch);
            }
        }
        return stringBuilder.toString();

    }


    public static void main(String[] args) {

    }

    public static void main6(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("hello");
        String str = stringBuilder.toString();


    }

    public static void main5(String[] args) {
        String str = "hello";
        str += " world";
        System.out.println(str);
    }

    public static void main4(String[] args) {
        String str1 = "abc";
        str1.intern();
        String s2 = "abc";
        System.out.println(str1 == s2);

    }

    public static void main3(String[] args) {
        String str = "abcab";
        String ret = str.replace("ab", "cd");

        System.out.println(ret);
        String ret2 = str.replaceAll("ac", "de");
        System.out.println(ret2);
        String ret3 = str.replaceFirst("ab", "c");
        System.out.println(ret3);
        String[] ret4 = str.split("a");
        System.out.println(Arrays.toString(ret4));
        String[] ret5 = str.split("a|b");
        String ret6 = str.substring(2, 4);
        System.out.println(ret6);
    }

    public static void main2(String[] args) {
        String str = String.valueOf(123);
        String st = String.valueOf(new Student("ly", 18));
        System.out.println(st);
        int val1 = Integer.parseInt("123");
        System.out.println(val1);
        double val2 = Double.parseDouble("12.5");
        System.out.println(val2);
        String str3 = "hello";
        String ret = str3.toUpperCase();
        System.out.println(ret);
        String str4 = "ADSDAI";
        String ret2 = str4.toLowerCase();
        System.out.println(ret2);
        char[] chars = str4.toCharArray();
        System.out.println(Arrays.toString(chars));
        String str5 = new String(chars);
        String ret3 = String.format("%d,%d%d", 12, 9, 8);
        System.out.println(ret3);


    }

    public static void main1(String[] args) {
        String str1 = "abc";
        String str2 = new String("abc");
        char[] chars = {'a', 'b', 'c'};
        String str3 = new String(chars);
        System.out.println(str1.equals(str2));
        int ret = str1.compareTo(str2);
        if (ret > 0)
            System.out.println("str1>str2");
        else if (ret == 0)
            System.out.println("str1=str2");
        else System.out.println("str1<str2");
        int ret1 = str1.compareToIgnoreCase(str2);
        System.out.println(str1.equalsIgnoreCase(str2));
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            System.out.println(ch);
        }
        System.out.println(str1.indexOf('c'));
        System.out.println(str1.indexOf('c', 3));
        System.out.println(str1.indexOf("ab"));
        System.out.println(str1.lastIndexOf('a'));
        System.out.println(str1.lastIndexOf('a', 2));

    }
}
